package top.frsf.envi;

import top.frsf.GameObject;
import top.frsf.iface.IDelayMovie;

import java.awt.*;
import java.util.Random;

/**
 * @BelongsProject: MiniPZ
 * @BelongsPackage: top.frsf.envi
 * @Author: FRSF
 * @CreateTime: 2022-09-06  22:19
 * @Description: 阳光类
 * @Version: 1.0
 */
public class Sun extends GameObject implements IDelayMovie {
    int moveLength = 0;
    static Image[] imgList = new Image[3];


    static {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        for (int i = 0; i < 3; i++) {
            imgList[i] = toolkit.getImage(EnvStart.PREFIX + "Sun" + (i + 1) + ".png");
        }
    }

    public Sun(String img, int x, int y, int width, int height) {
        super(img, x, y, width, height);
    }

    public static Sun getSunObj() {
        Random random = new Random();
        int x = random.nextInt(700) + 60;
        int y = random.nextInt(300) + 60;
        return new Sun("",
                x, y, 110, 110);
    }

    @Override
    public void paintSelf(Graphics g) {
        if (moveLength < 3) {
            g.drawImage(imgList[0], getX() + 30, getY() + 30, null);
        } else if (moveLength < 6) {
            g.drawImage(imgList[1], getX() + 20, getY() + 20, null);
        } else {
            g.drawImage(imgList[2], getX(), getY(), null);
        }
        move();
    }

    public void move() {
        if (moveLength < 60) {
            setY(getY() + 1);
            moveLength++;
        }
    }
}
